package com.blb.orderservice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.common.entity.Order;
import com.blb.common.entity.Product;
import com.blb.common.entity.User;
import com.blb.common.feign.ProductServiceFeignClient;
import com.blb.common.feign.UserServiceFeignClient;
import com.blb.common.util.ResponseResult;
import com.blb.orderservice.mapper.OrderMapper;
import com.blb.orderservice.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private ProductServiceFeignClient productServiceFeignClient;

    @Autowired
    private UserServiceFeignClient userServiceFeignClient;

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Order getOrderById(Long id) {
        Order order = orderMapper.selectById(id);
        //使用feign客户端调用商品服务
        ResponseResult<Product> entity = productServiceFeignClient.getProductById(order.getProductId());
        order.setProduct(entity.getData());
        //调用用户服务
        ResponseResult<User> result = userServiceFeignClient.getUserById(order.getUserId());
        order.setUser(result.getData());
        return order;
    }
}
